package com.lapck.car1;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

public class Pista extends View{

	private float x;
	private float y;
	
	private float posx;
	private float posy;

	private float pxmovx;
	private float pxmovy;
	
	
	
Bitmap pistabmp;

	Pista(Context c,int pistaid, float wd, float hg){
		super(c);
		pistabmp = BitmapFactory.decodeResource(c.getResources(),pistaid);
		x = 0;
		y= 0;
		posx=x;
		posy=y;
		pxmovx = 0;
		pxmovy = 0;
	}
	@Override
	protected void onDraw(Canvas canvas){
		super.onDraw(canvas);
		
		canvas.save();
		canvas.drawBitmap(pistabmp, x+100,y+100,null);
		//canvas.translate(x, y);
		canvas.restore();
	}
	public void muevepista(float mvx,float mvy){
		//Log.v("mensaje", "X="+x +" Y="+y );
		posx = x;
		posy=y;


		//TranslateAnimation anim = new TranslateAnimation(posx, x ,posy, y);
		pxmovx = mvx;
		pxmovy= mvy;
		x -= mvx;
		y -= mvy;			
	
		
		TranslateAnimation anim = new TranslateAnimation(mvx, 0 ,mvy, 0);
	
		Log.v("mensaje","x="+x+" y="+y+" posx="+posx+" posy="+posy +" mvx="+mvx +" mvy="+mvy);

		anim.setDuration(1000);
		posx = x;
		posy=y;		


		//Log.v("mensaje", "mvX="+mvx +" mvY="+mvy );
		this.startAnimation(anim);

		}
}
